package com.example.demo.base.login.controller;


import com.example.demo.base.login.dto.AdminRegisterVo;
import com.example.demo.base.login.dto.AdminRegisterWebVo;
import com.example.demo.base.login.dto.LoginVo;
import com.example.demo.base.login.dto.LoginWebVo;
import com.example.demo.base.login.service.ExamUserService;
import com.example.demo.dto.ResponseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RequestMapping("/register")
@RestController
public class RegisterController {
    @Autowired
    ExamUserService examUserService;

    /**
     * 1.公司用户创建
     * 用户账号，和权限需要加密传输
     * 默认密码 123456
     * 角色可以多个，用角色id以及逗号组成
     * 身份必输：
     * superAdmin("1", "超级管理员"),
     * companyAdmin("2", "公司管理员"),
     * companyUser("3", "公司用户"),
     * normalUser("4", "普通用户"),
     * @param adminRegisterVo
     * @param request
     * @return
     */
    @PostMapping("/adminRegister")
    public ResponseDto adminRegister(@Valid @RequestBody AdminRegisterVo adminRegisterVo, HttpServletRequest request) {
        return new ResponseDto<>().buildSucceedHasData(examUserService.adminRegister(adminRegisterVo, request));
    }


    /**
     * 1.普通用户注册
     * 用户账号，密码，验证码需要加密传输
     * @param adminRegisterVo
     * @param request
     * @return
     */
    @PostMapping("/userRegister")
    public ResponseDto userRegister(@Valid @RequestBody AdminRegisterVo adminRegisterVo, HttpServletRequest request) {
        return new ResponseDto<>().buildSucceedHasData(examUserService.userRegister(adminRegisterVo, request));
    }
}
